import pika
import time

# import pymysql

credentials = pika.PlainCredentials('guest', 'guest')
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', 5672, '/', credentials))
channel = connection.channel()
#channel.exchange_declare(exchange='hello', type='fanout')
#channel.queue_declare(queue='i2p_test')
#channel.queue_bind(exchange='i2p_', queue='i2p_test')


# for x in range(1, 10):
#    channel.basic_publish(exchange='', routing_key='hello', body='hello world %s' % (x))


def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)
    ch.basic_ack(delivery_tag=method.delivery_tag)


# my = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123456', db='i2p')
# cur = my.cursor(cursor=pymysql.cursors.DictCursor)
# cur.execute("select * from t_manage_role")
# ret = cur.fetchall()
# print(ret)
# my.commit()
# cur.close()
# my.close()

channel.basic_consume(callback, queue='hehe', no_ack=False)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
